package com.leo.spring.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 类描述
 *
 * @author razor.liu
 * @version 1.0
 * @date 2021/11/5 10:16 下午
 */
@Service
public class StrategyFactory {

    @Autowired
    Map<String, IStrategy> strategys = new ConcurrentHashMap<>(3);

    public IStrategy getStrategy(String component) throws Exception{
        IStrategy strategy = strategys.get(component);
        if(strategy == null) {
            throw new RuntimeException("no strategy defined");
        }
        return strategy;
    }
}
